package com.tmall.testgen.plugin.views.action;

import java.util.ArrayList;
import java.util.Map;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.TreeViewer;

import com.tmall.testgen.client.ClientDataCenter;
import com.tmall.testgen.client.commond.SendCommondInstance;
import com.tmall.testgen.client.socket.SocketClient;
import com.tmall.testgen.common.bo.interact.back.InterceptInfo;
import com.tmall.testgen.plugin.views.vo.TreeParent;
import com.tmall.testgen.server.socket.CommondEnum;

/**
 * 清除
 * 
 * @author star
 * 
 */
public class ClearAction extends Action {
	private TreeParent interceptRoot;
	//private TreeParent mockRoot;
	private TreeViewer viewer;
	
	public ClearAction() {
		setText("清除");
		setToolTipText("clear test");
		setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.USED_CLEAR));
	}

	public void run() {
		if(!SocketClient.getInstance().isStart())
			return;
		SendCommondInstance.getSendCommond().sendCommond(CommondEnum.Clear);
		ClientDataCenter.getInstance().setInfoes(new ArrayList<InterceptInfo>());
		interceptRoot.removeAllChildren();
		viewer.refresh();
		 Map<String, ArrayList<String>> intClassAndMethods=  ClientDataCenter.getInstance().getLoadedInterceptClassAndMethods();
		 if(intClassAndMethods!=null&&intClassAndMethods.size()>0){
			 CheckInterceptInfoByCoverAction.addAllToRoot(interceptRoot, intClassAndMethods, new ArrayList<InterceptInfo>());
		 }
		 
		 
		//mockRoot.removeAllChildren();
//		
//		 Map<String, ArrayList<String>> mockClassAndMethods=  ClientDataCenter.getInstance().getLoadedMockClassAndMethods();
//		 if(mockClassAndMethods!=null&&mockClassAndMethods.size()>0){
//			 CheckInterceptInfoByCoverAction.addAllToRoot(mockRoot, mockClassAndMethods, new ArrayList<InterceptInfo>());
//		 }
//		
//		viewer.refresh();
	}
	

	public TreeParent getInterceptRoot() {
		return interceptRoot;
	}

	public void setInterceptRoot(TreeParent interceptRoot) {
		this.interceptRoot = interceptRoot;
	}

//	public TreeParent getMockRoot() {
//		return mockRoot;
//	}
//
//	public void setMockRoot(TreeParent mockRoot) {
//		this.mockRoot = mockRoot;
//	}

	public TreeViewer getViewer() {
		return viewer;
	}

	public void setViewer(TreeViewer viewer) {
		this.viewer = viewer;
	}
	
	
	
}
